/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.prototype.vaadin;

import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 *
 * @author zineddine
 */
public class NewMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException, InterruptedException, InterruptedException, InterruptedException, InterruptedException, ExecutionException {
        PremiereConnection test;
//        System.out.println("zino");
        test = new PremiereConnection("http://sourceforge.net/directory/os:windows/license:publicdomain/"); 
       
        int numWorkers = test.nbPage();
        numWorkers--;    
       
        ExecutorService pooldynamique = Executors.newCachedThreadPool();
        
            
        JobThread workers[] = new JobThread[numWorkers];
        Future<ConcurrentHashMap<String,String>> futures[] = new Future[numWorkers];
        
        for(int i=0;i<numWorkers;i++){
            //Thread.sleep(2000);

            workers[i] = new JobThread(test.urlPage().get(i));
            futures[i]= pooldynamique.submit(workers[i]);
        }
             
        pooldynamique.shutdown();
           
        for (int i = 0; i < numWorkers; i++) {
            try {    
                test.concurrentMap.putAll((futures[i].get()));
            } catch (Exception e) {}
        }     
                        
        for(ConcurrentHashMap.Entry<String,String> entry : test.concurrentMap.entrySet()) {
           
            String cle = entry.getKey();
            String valeur = entry.getValue();
            System.out.println("Nom: "+cle +" Lien: "+valeur);
            CmdLineRecover c = new CmdLineRecover();
            c.getCodeURL("http://sourceforge.net"+valeur);
       }
       
    
    }
}
